const TodoService = require('../services/TodoService');
const TodoController = {
    getAllTodos: async (req, resp) => {
        const queryResult = await TodoService.getAllTodos();
        resp.send(queryResult);
    },
    getDones: async (req, resp) => {
        const bid = req.params["bid"];
        console.log('待办的参数', bid);
        const queryResult = await TodoService.getDones(bid);
        resp.send(queryResult);
    },
    getUpDones: async (req, resp) => {
        const bid = req.params["bid"];
        console.log('略略略', bid);
        const queryResult = await TodoService.getUpDones(bid);
        resp.send(queryResult);
    },
    changeState: async (req, resp) => {
        const { tid, state } = req.body;
        console.log(tid, state);
        const changeResult = await TodoService.changeState(tid, state);
        if (changeResult.changedRows === 1) {
            resp.send({ ok: 1 });
        } else {
            resp.send({ ok: 0 });
        }
    },
    newTodoByUid: async (req, resp) => {
        const { uid, date, content } = req.body;
        const newResult = await TodoService.newTodoByUid(uid, date, content);
        if (newResult === 1) {
            resp.send({ ok: 1 });
        } else {
            resp.send({ ok: 0 });
        }
    },
    deleteTodoByTid: async (req, resp) => {
        const tid = req.params["tid"];
        const deleteResult = await TodoService.deleteTodoByTid(tid);
        if (deleteResult === 1) {
            resp.send({ ok: 1 });
        } else {
            resp.send({ ok: 0 });
        }
    },
}
module.exports = TodoController